
<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" id="title">顶部选项卡-div模式</h1>
			<a class="mui-icon mui-icon-bars mui-pull-right" id="btnSelect" ></a>
		</header>
		<div class="mui-content">
			<div class="mui-slider-indicator mui-segmented-control mui-segmented-control-inverted mui-pull-left" style="border: red solid 0px;">
				<a class="mui-control-item mui-active" v-on:click="loadData('hot')">热门</a>
				<a class="mui-control-item" v-on:click="loadData('new')">新书</a>
				<a class="mui-control-item" v-on:click="loadData('reputation')">好评</a>
				<a class="mui-control-item" v-on:click="loadData('over')">完结</a>
				<a class="mui-control-item" v-on:click="loadData('monthly')">包月</a>
			</div>
			<div id="scroll" class="mui-scroll-wrapper" style="margin-top: 40px;">
				<div class="mui-scroll">
					<!--<div class="mui-card">s</div>-->
					<div class="mui-card" style="margin-bottom: 35px;">
						<ul class="mui-table-view mui-table-view-chevron">
							<li class="mui-table-view-cell mui-media" v-for="item in books">
								<a class="mui-navigate-right" v-on:click="openWindow(item)">
									<img class="mui-media-object mui-pull-left" v-bind:src="item.cover">
									<div class="mui-media-body">
										<span v-html="item.title">CBD</span>
										<p class='mui-ellipsis' v-html="item.shortIntro">烤炉模式的城，到黄昏，如同打翻的调色盘一般.</p>
									</div>
								</a>
							</li>
						</ul>
					</div>
				</div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<!--<script src="../js/mui.picker.min.js"></script>-->
		<script src="../js/mui.picker.js"></script>
		<script src="../js/mui.poppicker.js"></script>
		<script src="../js/vue.min.js"></script>
		<script src="../js/app.js"></script>
		<script src="../js/categoryinfo.js"></script> 
		<script>
			mui.init({
				swipeBack:true, //启用右滑关闭功能
			  	pullRefresh : {
			    	container:"#scroll",//待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
			    	up : {
				      	height:50,//可选.默认50.触发上拉加载拖动距离
				      	auto:true,//可选,默认false.自动上拉加载一次
				      	contentrefresh : "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
				      	contentnomore:'没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
				      	callback :appendData //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
				    }
			  	}
			});
			var vm = new Vue({
				el: '.mui-content',
				data: {
					gender:"",
					major:"",
					mins:[],
					type:"hot",
					minor:"",
					start:0,
					limit:20,
					total:0,
					books:[],
				}
			});
			mui.plusReady(function(){
//				mui('#scroll').scroll({
//					indicators: true //是否显示滚动条
//				});
				var self = plus.webview.currentWebview();
				vm.gender = self.gender;
				vm.major = self.name;
				
				var title = document.getElementById("title");
				title.innerHTML = self.name + "-热门";
				
				//普通示例
				var typePicker = new mui.PopPicker();
				typePicker.setData([{
					value: 'hot',
					text: '热门'
				}, {
					value: 'new',
					text: '新书'
				}, {
					value: 'reputation',
					text: '好评'
				}, {
					value: 'over',
					text: '完结'
				}, {
					value: 'monthly',
					text: '包月'
				}]);
				var btnSelect = document.getElementById('btnSelect');
				btnSelect.addEventListener('tap', function(event) {
					typePicker.show(function(items) {
						//userResult.innerText = JSON.stringify(items[0]);
						title.innerHTML = self.name + "-"+items[0].text;
						
						//返回 false 可以阻止选择框的关闭
						//return false;
					});
				}, false);
					
				loadData('hot');
			});
			
			function loadData(type){
				console.log("type="+type);
				vm.type = type;
				vm.start = 0;
				plus.nativeUI.showWaiting("正在加载数据，请稍等...");
				/*https://api.zhuishushenqi.com/book/by-categories?gender=male&type=hot&major=%E5%A5%87%E5%B9%BB&minor=&start=0&limit=20*/
				var ajaxUrl = "https://api.zhuishushenqi.com/book/by-categories?gender="+vm.gender+"&type="+type+"&major="+vm.major+"&minor=&start="+vm.start+"&limit="+vm.limit;
				console.log(ajaxUrl);
				mui.getJSON(ajaxUrl, {}, function(rsp) {
					plus.nativeUI.closeWaiting();
					console.log(JSON.stringify(rsp));
					if(rsp.ok && rsp.ok == false){
						plus.nativeUI.alert(rsp.msg);
						return;
					}
					if(rsp.ok && rsp.ok == true){
						//vm.keyValue = rsp._id;
						vm.total = rsp.total;
						var books = rsp.books;
						books.forEach(function(item){
							//console.log(item.cover);
							item.cover ="http://statics.zhuishushenqi.com"+ item.cover;
						});
						vm.books = books;
//						if(vm.books.length < vm.total)
//							mui('divContainer').pullRefresh().enablePullupToRefresh();
//						else
//							mui('divContainer').pullRefresh().disablePullupToRefresh();
					}
				});
			}
			
			function appendData(){
				vm.start = vm.start + 1;
				plus.nativeUI.showWaiting("正在加载数据，请稍等...");
				/*https://api.zhuishushenqi.com/book/by-categories?gender=male&type=hot&major=%E5%A5%87%E5%B9%BB&minor=&start=0&limit=20*/
				var ajaxUrl = "https://api.zhuishushenqi.com/book/by-categories?gender="+vm.gender+"&type="+vm.type+"&major="+vm.major+"&minor=&start="+vm.start+"&limit="+vm.limit;
				console.log(ajaxUrl);
				mui.getJSON(ajaxUrl, {}, function(rsp) {
					plus.nativeUI.closeWaiting();
					console.log(JSON.stringify(rsp));
					if(rsp.ok && rsp.ok == false){
						plus.nativeUI.alert(rsp.msg);
						return;
					}
					if(rsp.ok && rsp.ok == true){
						//vm.keyValue = rsp._id;
						vm.total = rsp.total;
						var books = rsp.books;
						books.forEach(function(item){
							//console.log(item.cover);
							item.cover ="http://statics.zhuishushenqi.com"+ item.cover;
							vm.books.push(item);/*附加内容*/
						});
						//vm.books = books;
						var nomore = vm.books.length >= vm.total;/*是否还有更多数据；若还有更多数据，则传入false; 否则传入true*/
						mui('#scroll').pullRefresh().endPullupToRefresh(nomore);
					}
				});
			}
			
			function openWindow(item){
				console.log(JSON.stringify(item));
				/*2019-05-19 侯连文 记录查看书*/
				app.setBook(item._id,item);
				mui.openWindow({id: 'bookinfo.html',url: 'bookinfo.html'
					,show: {aniShow: 'pop-in'}
					,extras: {    //extras里面的就是参数了
	                	keyValue: item._id,
	                	title:item.title,
	                	monthRank:item.monthRank,
	                	totalRank:item.totalRank,
	           		}
					,waiting: {
						autoShow: true, //自动显示等待框，默认为true
	           		}
  				});
			}
		</script>

	</body>

</html>